﻿using Coldairarrow.Entity.DataView;
using Coldairarrow.Entity.DTO;
using Coldairarrow.Util;
using EFCore.Sharding;
using LinqKit;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Linq.Expressions;
using System.Threading.Tasks;

namespace Coldairarrow.Business.DataView
{
    public partial class blade_visual_configBusiness : BaseBusiness<blade_visual_config>, Iblade_visual_configBusiness, ITransientDependency
    {
        public blade_visual_configBusiness(IDbAccessor db)
            : base(db)
        {
        }

        #region 外部接口
        public async Task<PageResult<blade_visual_configDTO>> GetDataListAsync(PageInput<ConditionDTO> input)
        {
            var where = LinqHelper.True<blade_visual_configDTO>();
            var search = input.Search;
            Expression<Func<blade_visual_config,blade_visual, blade_visual_configDTO>>select = (a,b) => new blade_visual_configDTO { visual_Name = b.title };
            select = select.BuildExtendSelectExpre();
            var q = from a in GetIQueryable().AsExpandable()
                    join b in Db.GetIQueryable<blade_visual>() on a.visual_id equals b.Id into ab
                    from b in ab.DefaultIfEmpty()
                    select @select.Invoke(a,b);
            //筛选
            if (!search.Condition.IsNullOrEmpty() && !search.Keyword.IsNullOrEmpty())
            {
                var newWhere = DynamicExpressionParser.ParseLambda<blade_visual_configDTO, bool>(
                    ParsingConfig.Default, false, $@"{search.Condition}.Contains(@0)", search.Keyword);
                where = where.And(newWhere);
            }
            return await q.Where(where).GetPageResultAsync(input);
        }

        public async Task<blade_visual_config> GetTheDataAsync(string id)
        {
            return await GetEntityAsync(id);
        }

        public async Task AddDataAsync(blade_visual_config data)
        {
            await InsertAsync(data);
        }

        public async Task UpdateDataAsync(blade_visual_config data)
        {
            await UpdateAsync(data);
        }

        public async Task DeleteDataAsync(List<string> ids)
        {
            
            await DeleteAsync(ids);
        }

   

        #endregion

        #region 私有成员

        #endregion
    }
}